package com.example.barcodescanner;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class AdActivity extends Activity {

	 private static final String MEDIA = "media";
	 
	 private static final int LOCAL_AUDIO = 1;
	    private static final int STREAM_AUDIO = 2;
	    private static final int RESOURCES_AUDIO = 3;

	    private static final int STREAM_VIDEO = 5;
	    private static final int RESOURCES_VIDEO = 6;
	    String productCode1;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad);
        /*Toast toast = Toast.makeText(getApplicationContext(),
				 getIntent().getExtras().getString("qrcontent"), Toast.LENGTH_LONG);
				 toast.show();*/
        
				 
		final String productCode = getIntent().getExtras().getString("qrcontent");
		if(productCode.startsWith("youtube"))
		productCode1=productCode.substring(8);
		else
			productCode1=productCode;
        TextView tv3 = (TextView) findViewById(R.id.textView3);
        tv3.setText("Product code : " + productCode1);
		ImageView adImage = (ImageView) findViewById(R.id.imageView2);
		//String resourcename = "R.drawable." + productCode;
		int resID = getResources().getIdentifier(productCode1 , "drawable", getPackageName());
		adImage.setImageResource(resID);

		ImageButton video = (ImageButton) findViewById(R.id.videoButton);
		video.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent browserIntent = new Intent(getApplicationContext(),
						ProductActivity.class);
				browserIntent.putExtra(MEDIA, STREAM_VIDEO);
				browserIntent.putExtra("productCode", productCode);
				startActivity(browserIntent);
			 
			}
		});
	
		ImageButton audio = (ImageButton) findViewById(R.id.audioButton);
		audio.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent browserIntent = new Intent(getApplicationContext(),
						AudioActivity.class);
				browserIntent.putExtra(MEDIA, STREAM_AUDIO);
				browserIntent.putExtra("productCode", productCode);
				startActivity(browserIntent);
			 
			}
		});
		
    
    }
    

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_ad, menu);
        return true;
    }
}
